/*
 * store_file.h
 *
 *  Created on: Feb 16, 2013
 *      Author: redchen
 */

#ifndef STORE_FILE_H_
#define STORE_FILE_H_

#include <lfs.h>
#include <vector.h>

/**
 * Block File
 */
typedef struct
{
    int32_t size;
    int64_t timestamp;
    char data[0];
} BFile;

typedef enum
{
    STORE_FILE_NORMAL, STORE_FILE_BLOCK
} StoreFileType;

typedef struct _StoreFile_ StoreFile;

//init

StoreFile* store_file_create(const char* path, const char* namespace, StoreFileType type, int32_t size);

StoreFile* store_file_open(const char* path);

//write

int store_file_wirte(StoreFile* file, void* data, int32_t size);

//read

int store_file_read(StoreFile* file, int64_t start, int64_t end, /*out:Vector<BFile>*/Vector* files);

//free

void store_file_destory(StoreFile* file);

//

const char* store_file_get_file_name(StoreFile* file);

const char* store_file_get_namespace(StoreFile* file);

StoreFileType store_file_get_type(StoreFile* file);

int32_t store_file_get_status(StoreFile* file);

void store_file_set_status(StoreFile* file, int32_t status);

int32_t store_file_allocated_size(StoreFile* file);

int32_t store_file_used_size(StoreFile* file);

#endif /* STORE_FILE_H_ */
